﻿$(function () {
    $("#city").change(function () {
        var city = $(this).val();
        var htArr = ["良村", "墟镇", "禾岗", "篁湾", "吕步", "霞村", "唐溪", "高村", "三丫", "六坊", "塔岗", "为民", "唐溪", "南村"];
        var jmArr = ["荷塘", "潮连", "棠下", "杜阮"];
        if (city == "荷塘") {
            $("#town").empty();
            for (var i = 0; i < htArr.length; i++) {
                $("#town").append("<option value='" + htArr[i] + "'>" + htArr[i] + "</option>");
            }
        }
        if (city == "江门") {
            $("#town").empty();
            for (var i = 0; i < jmArr.length; i++) {
                $("#town").append("<option value='" + jmArr[i] + "'>" + jmArr[i] + "</option>");
            }
        }
    });

    function isleapyear(year) {
        if ((year % 4 == 0) && (year % 100 != 0)) {
            return true;
        } else if (year % 400 == 0) {
            return true;
        } else {
            return false;
        }
    }

    function inArray(elem, array) {
        for (var i = 0, length = array.length; i < length; i++) {
            if (array[i] == elem)
                return true;
        }
        return false;
    }

    $("#BornMonth").change(function () {
        var year = $("#BornYear").val();
        var month = $(this).val();
        var month31 = [1, 3, 5, 7, 8, 10, 12];
        var month30 = [4, 6, 9, 11];
        var days = 0;
        if (month == 2) {
            if (isleapyear(year)) {
                days = 29;
            }
            else {
                days = 28;
            }
        }
        else if (inArray(month, month31)) {
            days = 31;
        }
        else if (inArray(month, month30)) {
            days = 30;
        }
        else {
            days = 0;
        }

        $("#BornDay").empty();

        for (var i = 1; i <= days; i++) {
            $("#BornDay").append("<option value='" + i + "'>" + i + "</option>");
        }        
    });

    $("#BornYear").change(function () {
        $("#BornMonth").val(1).trigger("change");
    });

    $("input[name=english_level]").change(function () {
        var content = "";

        $("input[name=english_level]:checked").each(function () {
            content += $(this).val() + " ";
        });

        $("#English").val(content);
    });
});